import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        // 菜单折叠
        toggle: false,
        username: 'admin',
        menuList: [
            {
                key: 0,
                title: '首页',
                icon: '&#xe603;',
                path: '/index'
            },
            {
                key: 1,
                title: '人员管理',
                icon: '&#xe789;',
                path: '/person_manage'
            },
            {
                key: 2,
                title: '事物管理',
                icon: '&#xe7c1;',
                path: 'drug_case_manage',
                children: [
                    {
                        key: '2-1',
                        title: '物件管理',
                        icon: '&#xe7c8;',
                        path: '/case_manage'
                    },
                    {
                        key: '2-2',
                        title: '物件研判',
                        icon: '&#xe7c9;',
                        path: '/person_involved'
                    }
                ]
            },
            {
                key: 3,
                title: '一键搜',
                icon: '&#xe79d;',
                path: '/search'
            }
        ],
        openTab: [
            {
                name: 'guide',
                title: '引导页',
                closable: false
            }
        ],
        activeIndex: ''
    },
    getters: {
        getToggle(state) {
            return state.toggle;
        }
    },
    mutations: {
        changeToggle(state) {
            state.toggle = !this.state.toggle;
        },
        add_tabs(state, data) {
            state.openTab.push(data);
        },
        delete_tabs(state, route) {
            let index = 0;
            for (let i of state.openTab) {
                if (i.route === route) {
                    break;
                }
                index++;
            }
            state.openTab.splice(index, 1);
        },
        set_active_tabs(state, index) {
            state.activeIndex = index;
        }
    },
    actions: {},
    modules: {}
});
